package net.caixiaomi.info.Lottery.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import net.caixiaomi.info.Lottery.adapter.TrendAdapter;
import net.caixiaomi.info.Lottery.model.BallLeaveEntity;
import net.caixiaomi.info.Lottery.model.TrendChartData;
import net.caixiaomi.info.R;
import net.caixiaomi.info.base.BaseFragment;
import net.caixiaomi.info.base.quickadapter.entity.MultiItemEntity;
import net.caixiaomi.info.util.Constants;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by suntian on 2018/8/17.
 */

public class TrendMainFragment extends BaseFragment {

    @BindView(R.id.trend_prize_title)
    LinearLayout mTrendPrize;

    @BindView(R.id.trend_heat_title)
    LinearLayout mTrendHeat;

    @BindView(R.id.trend_listview)
    RecyclerView mListview;

    private TrendAdapter mAdapter;

    private TrendChartData data;

    private int mType; //0开奖号码 3红球冷热 4蓝球冷热

    @Override
    protected int fragmentLayout() {
        return R.layout.trend_frag_layout;
    }

    public void setmType(int mType) {
        this.mType = mType;
    }

    @Override
    protected void onFragmentCreated(View view, @Nullable Bundle savedInstanceState) {
        mListview.setLayoutManager(new LinearLayoutManager(getActivity()));

        mListview.setAdapter(mAdapter);
        switch (mType){
            case 0:
                mTrendPrize.setVisibility(View.VISIBLE);
                mTrendHeat.setVisibility(View.GONE);
                break;
            case 3:
                mTrendPrize.setVisibility(View.GONE);
                mTrendHeat.setVisibility(View.VISIBLE);
                break;
            case 4:
                mTrendPrize.setVisibility(View.GONE);
                mTrendHeat.setVisibility(View.VISIBLE);
                break;
        }

    }

    public void initData(TrendChartData data){
        if(data==null){
            return;
        }
        mAdapter=new TrendAdapter(null);
        mAdapter.setType(mType);
        if(mListview!=null){
            mListview.setAdapter(mAdapter);
        }
        this.data=data;
        switch (mType){
            case 0:
                List<MultiItemEntity> lottoNums=new ArrayList<>();
                lottoNums.addAll(data.getLottoNums());
                mAdapter.setNewData(lottoNums);

                break;
            case 3:
                List<MultiItemEntity> list0=new ArrayList<>();
                list0.addAll(data.getPreHeatColds());
                mAdapter.setNewData(list0);

                break;
            case 4:
                List<MultiItemEntity> list1=new ArrayList<>();
                list1.addAll(data.getPostHeatColds());
                mAdapter.setNewData(list1);

                break;
        }
        mAdapter.notifyDataSetChanged();
    }

}
